import React, { Component } from 'react'
import './css/09-maizuo.css'
import Film from './maizuocomponent/Film'
import Center from './maizuocomponent/Center'
import Cinema from './maizuocomponent/Cinema'
export default class App extends Component {
  state = {
    list: [{ id: 1, text: '电影' }, { id: 2, text: '影院' }, { id: 3, text: '我的' }],
    active: 0
  }
  witch() {
    switch (this.state.active) {
      case 0:
        return <Film></Film>
      case 2:
        return <Center></Center>
      case 1:
        return <Cinema></Cinema>
      default:
        return null
    }
  }
  render() {
    return (
      <div>
        {
          this.witch()
        }
        <ul>
          {
            this.state.list.map((item, index) => 
              <li className={this.state.active === index ? 'active' : ''} key={item.id} onClick={() => this.handleClick(index)}>{item.text}</li>
            )
          }
        </ul>
      </div>
    )
  }
  handleClick(index) {
    this.setState({
      active: index
    })
  }
}
